
# -*- coding: utf-8 -*-

import tornado.web
from models.User import User
from models.Image import Image
from config import Config
from controllers.BaseSocketController import BaseSocketController

class UploadPhotoSocketController(BaseSocketController):
	def process(self, cv_image):
		user = User.get(User.username == self.get_secure_cookie('user'))
		if user:
			res = Image(user=user).persist(cv_image, Config.PHOTONUMBER)
			self.write_message(res)
			return
		raise tornado.web.HTTPError(400)
